﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

using System.Net;
using System.Net.Sockets;

using RetroNET.Network;

namespace RetroNET
{
	public partial class RetroNETCore
	{
		private void ParseClientCommand(RNClient client, string cmd)
		{
			string[] cmdTokens = cmd.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

			//Console.WriteLine("[" + client.sockIn.RemoteEndPoint + "] Trying to parse \"" + cmd + "\"...");
			//SendDataToClient(client, "\r\n[NODE] Received command " + cmd);
			
			switch (cmdTokens[0].ToUpper())
			{
				case "QUIT":
				case "EXIT":
				case "BYE":
					SendDataToClient(client, "\r\n[NODE] Goodbye!");
					client.sockIn.Close();
					break;

				case "VERSION":
				case "VER":
					SendDataToClient(client, "Current RetroNet version: " + version);
					break; 
				
				case "TIME":
					SendDataToClient(client, "Server date/time: " + DateTime.Now.ToString());
					break;
			
				default:
					if (delHandleClientInput != null && delHandleClientInput(client, cmd))
					{
						//(client, "[NODE] Command successfully handled upstream.");
						break;
					}
					else
					{
						//SendDataToClient(client, "[NODE] Unable to handle command upstream, falling back...");
					}

					SendDataToClient(client, "[NODE] Unrecognized command " + cmd);
					break;
			}

		}

	}
}